package com.maoyan.quickdevelop.admin.controller.system.dqroom;

import cn.hutool.core.date.DateUtil;
import com.maoyan.quickdevelop.common.core.AjaxResult;
import com.maoyan.quickdevelop.common.core.domain.dqroom.DqBookInfo;
import com.maoyan.quickdevelop.system.domain.vo.DqRoomVO;
import com.maoyan.quickdevelop.system.service.IDqBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/dqbook")
public class DqBookController {

    @Autowired
    private IDqBookService iDqBookService;

    @GetMapping(value = "/test")
    private AjaxResult testJRebel() {
        return AjaxResult.success("测试成功!!!!!");
    }

    @GetMapping("/check")
    public AjaxResult checkRoomIsUse(String roonNumber, String bookDate, String endDate) {
        Integer integer = iDqBookService.checkRoomIsUse(roonNumber, bookDate, endDate);
        return AjaxResult.success("查询成功", integer);
    }

    @PostMapping("/book")
    public AjaxResult bookRoom(@RequestBody DqBookInfo dqBookInfo) {
        Integer integer = iDqBookService.bookRoom(dqBookInfo.getUsername(), dqBookInfo.getPhone(), dqBookInfo.getRemarks(), dqBookInfo.getRoomId(), DateUtil.formatDateTime(dqBookInfo.getBookDate()), DateUtil.formatDateTime(dqBookInfo.getEndDate()));
        return AjaxResult.success("预定成功", integer);
    }

    @GetMapping("/find")
    public AjaxResult selectBookInfoByUsername(String username) {
        List<DqBookInfo> dqBookInfos = iDqBookService.selectBookInfoByUsername(username);
        return AjaxResult.success("查询成功", dqBookInfos);
    }

    @GetMapping("/empty")
    public AjaxResult selectEmptyRoom(Long dqRoomid) {
        List<String> strings = iDqBookService.selectEmptyRoom(dqRoomid);
        return AjaxResult.success("查询成功", strings);
    }

    @PostMapping("/use")
    public AjaxResult selectUseRoom(@RequestBody DqRoomVO dqRoomId) {
        List<String> strings = iDqBookService.selectUseRoom(dqRoomId.getDqRoomId(), dqRoomId.getBookDate(), dqRoomId.getEndDate());
        return AjaxResult.success("查询成功", strings);
    }

}
